home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 008a / intr26a.zip / INTERRUP.PRI < prev    next >
Text File  |  1990-04-28  |  5KB  |  104 lines

  1.                      iAPX 86 Interrupt Primer
  2.                      ------------------------
  3.  
  4.                           by Ralf Brown
  5.                               12/87
  6.                            Updated 6/88
  7.                Updated 4/90
  8.  
  9.  
  10. What is an interrupt?
  11.    An interrupt is a hardware signal that tells the CPU to 
  12.    temporarily stop what it is doing and go do something else.  
  13.    Without interrupts, the CPU would have to constantly check for 
  14.    external events; with interrupts, the CPU can work on 
  15.    something else and still respond to an event as soon as it 
  16.    occurs. 
  17.  
  18.    CPUs typically have an instruction to disable interrupts for 
  19.    use when a section of code has to run without being disturbed 
  20.    by external events.  Because of this, most CPUs also have a 
  21.    special interrupt called a Non-Maskable Interrupt (NMI), which 
  22.    is responded to even when all other interrupts are disabled.  
  23.    The NMI is used to signal calamities such as memory failure or 
  24.    imminent power loss.
  25.  
  26. Why so many different interrupts?
  27.    The 8086 family of processors has the ability to recognize 256 
  28.    different interrupts.  They also have the ability to let a 
  29.    program invoke any of these interrupts with a special 
  30.    instruction, known as a software interrupt (as opposed to a 
  31.    hardware interrupt which is signalled from outside the 
  32.    processor).  Software interrupts are treated just like 
  33.    hardware interrupts, except that they are never disabled and 
  34.    do not result in an acknowledgement to other chips in the 
  35.    computer.  The software interrupt instruction on the 8086 
  36.    family is called INT, and is given the number of the 
  37.    interrupt.  Thus an INT 21h instruction invokes interrupt 
  38.    number 33 decimal.
  39.  
  40.    Other processors also have software interrupts, though they 
  41.    often use different names, such as the Motorola 68000 family 
  42.    TRAP instruction, the Intel 8080 RST (ReSeT) instruction, or 
  43.    many mainframes' SVC (SuperVisor Call). 
  44.  
  45.    Since a program can invoke an interrupt by number rather than 
  46.    by its address (as it has to in calling subroutines), 
  47.    interrupts are a convenient way of providing services without 
  48.    having to recompile a program whenever the address of the code 
  49.    providing the service changes.  This also allows a user 
  50.    program to enhance the services provided by directing the 
  51.    interrupt to itself.  These enhanced services can then be made 
  52.    available to other programs.
  53.  
  54. How does an interrupt work?
  55.    The 8086 reserves the lowest 1024 bytes of memory for a table 
  56.    containing the addresses for each of the 256 possible 
  57.    interrupts.  When an interrupt occurs (hardware or software), 
  58.    the processor multiplies its number by 4 and looks at the 
  59.    resulting memory location to find the address of the piece of 
  60.    code which handles the interrupt.  It then places the current 
  61.    address in the program and the processor flags on the stack, 
  62.    and jumps to the beginning of the interrupt handler.
  63.  
  64.    When the interrupt handler finishes, it invokes a special 
  65.    instruction to return from the interrupt.  This instruction 
  66.    takes the previously saved flags and program address off of 
  67.    the stack and places them back in the appropriate registers in 
  68.    the CPU.
  69.  
  70.    The interrupt handler has to be careful to preserve any 
  71.    registers that it uses which are not used to communicate 
  72.    results to the program that invoked the interrupt.  If the 
  73.    interrupt can be triggered by a hardware interrupt (only 
  74.    certain ones can on IBM PC's, XT's, and AT's), then the 
  75.    interrupt handler has to preserve ALL registers, since the 
  76.    interrupt could have happened anywhere.
  77.  
  78.  
  79. GLOSSARY
  80. --------
  81. API (Application Program[ming] Interface)
  82.    An API is the set of function calls and services that a
  83.    program makes available to other processes (applications).
  84.    Each function or service has a set format which specifies
  85.    the values to be supplied by the caller and the values
  86.    which are returned.    Because of this interface
  87.    specification, the underlying organization of the
  88.    function or service can be changed without affecting the
  89.    applications which use it.  For example, the DOS INT 21h
  90.    file access functions remained unchanged between DOS 2.x
  91.    and DOS 3.x, even though the internal data structures and
  92.    code organization changed significantly.
  93.  
  94. NMI (Non-Maskable Interrupt)
  95.    Most external (hardware) interrupts can be disabled by the
  96.    CLI (CLear Interrupt enable flag) instruction when the CPU
  97.    is executing critical code that should not be interrupted,
  98.    such as switching from one stack to another.  However, there
  99.    are some situations so dire that the CPU must act on them
  100.    immediately no matter what else it is doing, even if it has
  101.    disabled interrupts.  The Non-Maskable Interrupt serves
  102.    precisely this purpose, as it cannot be disabled (masked) by
  103.    the CPU.
  104.